package com.car.framework;

import com.car.comm.Logger;
import com.car.comm.Variable;
import com.car.datalayer.http.HttpEngineMultiThread;
import com.car.datalayer.http.IHttpEngine;
import com.car.postoffice.CAddress;
import com.car.postoffice.IMailBox;
import com.car.postoffice.PostOffice;
import com.car.postoffice.mailbox.MemoryMailBox;

/**
 *  整个框架的构建类，黏贴剂
 * @author Xairy
 */
class FrameworkFactory {
	private static PostOffice office;
	private static IHttpEngine httpEngine;
	private static BitmapMapping bitmapMapping;
	private static ImageManager imageManager;
	
	static{
		Logger.LogDebug("FrameworkFactory Static Begin");
		office = new PostOffice();
		httpEngine = new HttpEngineMultiThread(Variable.httpThreadNum);
		bitmapMapping = new BitmapMapping();
		
		// 注册所有的组件
		CHttpAdaptor httpAdaptor = new CHttpAdaptor(office, httpEngine);
		office.RegisterTransaferWorker(Variable.httpGetScheme, httpAdaptor);
		office.RegisterTransaferWorker(Variable.httpPostScheme, httpAdaptor);
		
		// 创建图像组件
		imageManager = new ImageManager();
		
		Logger.LogDebug("FrameworkFactory static End");
	}
	
	public static IMailBox CreateMailBox(final CAddress addr){
		return new MemoryMailBox();
	}
	
	public static PostOffice GetOffice(){
		return office;
	}
	
	public static IDataMapping GetBitmapMapping(){
		return bitmapMapping;
	}
	
	public static ImageManager GetImageManager(){
		return imageManager;
	}
}
